<!--
 * @description  : 涉案物资查询
 * @descriptionDetail: 涉案物资查询
 * @copyright    : 浙江烟草
 * @author       : dw
 * @create       : 2022-10-09 22:21:21
-->

<template>
  <view class="page">
    <!-- #ifdef H5-ONLY -->
    <theme-navbar :is-white="false" :title="navTitle" :custom-back="goBack" style="z-index: 99999">
    </theme-navbar>
    <!-- #endif -->
    <view class="content u-page">
      <!-- 内容区 -->
      <u-image class="head-img" :width="getImgWidth()" src="/static/store/head_banner.png" mode="widthFix"></u-image>
      <view class="grid-lay">
        <u-grid :col="3" :border="false">
          <u-grid-item :index="index" v-for="(item, index) in list" :key="item.key" @click="gridClick(item)">
            <u-image :src="item.iconPath" :width="120" mode="aspectFit" :height="120"></u-image>
            <view class="grid-text">
              {{ item.text }}
            </view>
          </u-grid-item>
        </u-grid>
      </view>
    </view>
  </view>
</template>

<script>
import commonService from '@/service/common/common.service.js';
import { aesDecrypt } from '@/common/crypto.util.js';
export default {
  components: {

  },
  onLoad() {
    let opt = this.getRouteParam() || {};
    if (opt.from == 'caseQrCode') {
      if (!this.$u.test.isEmpty(opt.storeId)) {
        this.$u.route({
          url: '/pages/store/storeList',
          type: "to",
          params: {
            storeId: opt.storeId,
          },
        });
      } else {
        this.$u.toast('二维码识别失败');
      }
    }
  },
  data() {
    return {
      list: [
        {
          iconPath: '../../static/store/stores.png',
          text: '盘库管理',
          bgColor: '#FEEAEA',
          key: 2,
          url: 'pages/store/inventoryManage/inventoryList',
        },
        {
          iconPath: '../../static/store/stock.png',
          text: '库存查询',
          bgColor: '#EBF2FF',
          key: 1,
          url: 'pages/store/storeList',
        },
        {
          iconPath: '../../static/store/doc.png',
          text: '单据管理',
          bgColor: '#EBF2FF',
          key: 3,
          url: 'pages/store/billManagement',
        },
        {
          iconPath: '../../static/store/escrow_articles.png',
          text: '物品代保管',
          bgColor: '#EBF2FF',
          key: 4,
          url: 'pages/store/articleManage',
        },
        // {
        //   iconPath: '../../static/store/handover.png',
        //   text: '变价案件',
        //   bgColor: '#EBF2FF',
        //   key: 8,
        //   url: 'pages/store/handover/handoverCaseList',
        // },
        // {
        //   iconPath: '../../static/store/erweima.png',
        //   text: '追溯码识别',
        //   bgColor: '#EBF2FF',
        //   key: 9,
        //   url: 'pages/store/handover/handoverScan',
        // },
      ],
      user: this.$store.state.userInfo,
    };
  },
  created() {
    this.getStoreBoxConfig();
  },
  methods: {
    gridClick(item) {
      console.log(item)
      if (item.url) {
        if (item.key == 6) {
        // if (item.key == 6 || item.key == 9) {
          this.$deviceApi.scan().then((res) => {
            const str = res
            // 获取加密配置
            commonService.getSysConfig("qr_code", "qr_code_key").then((res) => {
              console.log(res);
              if (res.code == 0 && res.success && res.msg) {
                let key = res.msg;
                let data = aesDecrypt(str, key);
                let params = JSON.parse(data);
                params.isAddGoods = false;
                params.formTo = 'scan';
                this.setRouteParam(params);
                this.$u.route(params.url);
              } else {
                this.$u.toast(res.msg);
              }
            }).catch((err) => {
              this.$u.toast(err.msg || "获取解密秘钥失败");
            })

          });

          // this.$deviceApi.scan().then((res) => {
          //   res.qrCode = "QR-B1301232024000003"
          //   let params = res
          //   params.isAddGoods = false
          //   this.setRouteParam(params);
          //   this.$u.route("/pages/store/box/storeBoxDetail");
          // });
        } else {
          this.setRouteParam(item.text);
          this.$u.route(item.url);
        }
      }
    },
    getImgWidth() {
      return (this.$u.sys().windowWidth - uni.upx2px(32)) + 'px';
    },
    getStoreBoxConfig() {
      commonService.getSysConfig("customize", "store-box-qr").then((res) => {
        if (res.code == 0 && res.success && res.msg) {
          let code = res.msg;
          if (!! code && (code.indexOf(this.user.orgCode) > -1 ||
			code.indexOf(this.user.cityOrgCode) > -1 ||
			code.indexOf(this.user.provOrgCode) > -1) ) {
            this.list.push(
              {
                iconPath: '../../static/store/handover.png',
                text: '变价案件',
                bgColor: '#EBF2FF',
                key: 8,
                url: 'pages/store/handover/handoverCaseList',
              },
              {
                iconPath: '../../static/store/box.png',
                text: '封箱码管理',
                bgColor: '#EBF2FF',
                key: 5,
                url: 'pages/store/storeBoxManage',
              },
              {
                iconPath: '../../static/store/erweima.png',
                text: '二维码识别',
                bgColor: '#EBF2FF',
                key: 6,
                url: 'pages/store/storeBoxManage',
              },
              {
                iconPath: '../../static/store/search.png',
                text: '智能查询',
                bgColor: '#EBF2FF',
                key: 7,
                url: 'pages/store/goods/goodsList',
              }
            )
          }
        }
      }).catch((err) => {
        console.log(err)
      })
    }
  },
};
</script>

<style lang="scss" scoped>
.head-img {
  width: 100%;
  padding: 16rpx 16rpx;
  margin: 0 auto;
}

.grid-lay {
  padding: 0 32rpx;
}

.grid-text {
  color: $u-main-color;
  margin-top: 24rpx;
  font-size: 30rpx;
}
</style>
